package org.example.aop.controller;

import jakarta.annotation.Resource;
import org.example.aop.entity.User;
import org.example.aop.service.UserService;
import org.example.aop.service.impl.UserServiceImplForMysql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

/**
 * org.example.aop.controller
 *
 * @author 莫磊
 * @description
 * @date 2025/7/27
 */
@Controller
public class UserController {

	/**
	 * Autowired和Qualifier两个配合可以实现通过名字进行自动装配
	 * 只是用Autowired时默认是通过类型进行自动装配
	 */
	@Autowired
	@Qualifier("user")
	User user;

	/**
	 * 先通过构造函数进行装配，然后再通过@Resource注解进行设置，所以构造函数中的值会被这个注解进行覆盖
	 * Resource没有指定name和type时，将属性名设置为name进行查找，找不到时通过类型进行装配
	 */
	// @Resource(name = "userServiceImplForMysql")
	@Resource(type = UserServiceImplForMysql.class)
	private UserService userService;

	public UserController(@Autowired @Qualifier("userServiceImplForOracle") UserService userService) {
		this.userService = userService;
	}

	public void addUser() {
		userService.addUser(user);
	}
}
